package com.snail.poker.web.action;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.json.annotations.JSON;

import com.snail.poker.model.Member;
import com.snail.poker.service.MemberService;
import com.snail.poker.uitls.Constant;

/**
 * 成员的Action
 * 
 * @author Snail
 * 
 */
public class MemberAction extends BaseAction {
	private final static Log log = LogFactory.getLog(MemberAction.class);
	private Member member;
	private MemberService memberManage;

	@JSON(serialize = false)
	public MemberService getMemberManage() {
		return memberManage;
	}

	public void setMemberManage(MemberService memberManage) {
		this.memberManage = memberManage;
	}

	public Member getMember() {
		return member;
	}

	public void setMember(Member member) {
		this.member = member;
	}

	public String login() {
		if (null == this.member) {
			super.putMessage("请输入用户名与密码.");
			return ERROR;
		}
		try {
			Member me = this.memberManage.login(this.member);
			super.session.put(Constant.MEMBER_SESSION_KEY, me);
			super.message = "登录成功.";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e);
			super.putMessage(e.getMessage());
			return ERROR;
		}
		return SUCCESS;
	}
}